package com.fanghuaman.user.controller;

import com.fanghuaman.model.common.vo.ResponseResult;
import com.fanghuaman.model.user.dto.ProductDto;
import com.fanghuaman.user.service.ShoppingCartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author shiminghui
 * @date 2024/12/8 15:33
 * @description: TODO
 */
@RestController
@Slf4j
@RequestMapping(value = "shopping")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;


    /**
     * 添加购物车
     *
     * @return
     */
    @PostMapping("addCart")
    public ResponseResult addCart(@RequestBody ProductDto productDto) {
        ResponseResult result = shoppingCartService.addCart(productDto);
        return result;
    }

    /**
     * 删除购物车记录
     *
     * @param cartId
     * @return
     */
    @DeleteMapping("delCart/{cartId}")
    public ResponseResult delCart(@PathVariable("productId") Long cartId) {
        ResponseResult result = shoppingCartService.delCart(cartId);
        return result;
    }

    /**
     * 获取购物车列表
     * @return
     */
    @GetMapping("getCart")
    public ResponseResult getCart() {
        ResponseResult result = shoppingCartService.getCart();
        return result;
    }

    /**
     * 清空购物车
     *
     * @return
     */
    @GetMapping("clearCart")
    public ResponseResult clearCart() {
        ResponseResult result = shoppingCartService.clearCart();
        return result;
    }

    /**
     * 支付
     *
     * @return
     */
    @GetMapping("paid")
    public ResponseResult paid() {
        ResponseResult result = shoppingCartService.paid();
        return result;
    }

    /**
     * 修改购物车
     *
     * @param cartId
     * @param productDto
     * @return
     */
    @PostMapping("updateCart/{cartId}")
    public ResponseResult updateCart(@PathVariable("cartId") Long cartId, @RequestBody ProductDto productDto) {
        ResponseResult result = shoppingCartService.updateCart(cartId, productDto);
        return result;
    }
}
